package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //入库时调用

    /**
     * setFieldValByName(arg1,arg2,arg3)
     * arg1:自动填充的字段名称
     * arg2：自动填充的值
     * arg3：metaObject 固定写的
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date =new Date();
        this.setFieldValByName("created",date,metaObject);
        this.setFieldValByName("updated",date,metaObject);
    }
    //更新操作时调用
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updated", new Date(), metaObject);
    }
}
